package com.lagou.homework.part01

/**
 * @author: yehw
 * @date: 2020/9/29 22:42
 * @description: 算啤酒瓶数量
 */
object Part01 {
  var bottle = 0
  def main(args: Array[String]): Unit = {
    val sumPrice: Int = 100 //有100元
    val singlePrice = 2 //每瓶2元
    val emptyBottleForBeer = 3 //三瓶空瓶子换一个啤酒
    val bottleCapForBeer = 5 //5个瓶盖换啤酒s
    println("空瓶可以换个数:" + calculateToBuyBeer(sumPrice / singlePrice, emptyBottleForBeer))
    bottle=0
    println("瓶盖可以换个数:" + calculateToBuyBeer(sumPrice / singlePrice, bottleCapForBeer))
  }
  def calculateToBuyBeer(initBottle: Int, replacementRule: Int): Int = {
    bottle += initBottle
    if (initBottle > replacementRule) {
      calculateToBuyBeer(initBottle%replacementRule+initBottle / replacementRule, replacementRule)
    }
    bottle
  }
}
